package com.link.common.packet.resp;

import com.link.common.util.BinaryUtils;
import com.link.common.util.NetUtils;
import io.netty.buffer.ByteBuf;

public record ChannelPacket (short id,
                             String channelName,
                             String serverIp,
                             short serverPort,
                             byte status,
                             short maxOnline,
                             short online

) {
    public void writeTo(ByteBuf buffer) {

        buffer.writeShort(id);
        BinaryUtils.writeString(buffer, channelName);
        BinaryUtils.writeString(buffer, serverIp);
        buffer.writeShort(serverPort);
        buffer.writeByte(status);
        buffer.writeShort(NetUtils.testNetDelay(serverIp));
        buffer.writeShort(maxOnline);
        buffer.writeShort(online);


    }
    public int length(){
        return 19+BinaryUtils.getStringLength(channelName)+BinaryUtils.getStringLength(serverIp);
    }


}
